import { createRouter, createWebHistory } from 'vue-router'
import Home from '../views/HomeOne.vue'
import HomeMain from '@/views/HomeMain.vue'
// 导入新创建的三个功能页
import FoodManage from '../views/FoodManage.vue'
import UserManage from '../views/UserManage.vue'
import RecipeManage from '../views/RecipeManage.vue'
import LoginView from '../views/LoginView.vue'
import RegisterView from '../views/RegisterView.vue'
import DataStatistics from '../views/DataStatistics.vue'
import SystemSettings from '../views/SystemSettings.vue'
import RoleManage from '../views/RoleManage.vue'
import PermissionManage from '../views/PermissionManage.vue'
import UserRoleManage from '../views/UserRoleManage.vue'
import RolePermissionManage from '../views/RolePermissionManage.vue'
const routes = [
  { 
    path: '/', 
    redirect: '/home' // 根路径重定向到首页布局
  },
  { 
    path: '/home', 
    name: 'Home', 
    component: Home, 
    redirect: '/home/HomeMain', // 默认显示首页
    children: [ // 子路由：在 HomeOne 的 <router-view> 中渲染
    { 
        path: 'HomeMain', 
        name: 'HomeMain', 
        component: HomeMain,
        meta: { title: '系统首页' }
      },
      { 
        path: 'food', 
        name: 'FoodManage', 
        component: FoodManage,
        meta: { title: '食材管理' }
      },
      { 
        path: 'user', 
        name: 'UserManage', 
        component: UserManage,
        meta: { title: '用户管理' }
      },
      { 
        path: 'role', 
        name: 'RoleManage', 
        component: RoleManage,
        meta: { title: '角色管理' }
      },
      { 
        path: 'permission', 
        name: 'PermissionManage', 
        component: PermissionManage,
        meta: { title: '权限管理' }
      },
      { 
        path: 'user-role', 
        name: 'UserRoleManage', 
        component: UserRoleManage,
        meta: { title: '用户角色管理' }
      },
      { 
        path: 'role-permission', 
        name: 'RolePermissionManage', 
        component: RolePermissionManage,
        meta: { title: '角色权限管理' }
      },
      { 
        path: 'recipe', 
        name: 'RecipeManage', 
        component: RecipeManage,
        meta: { title: '食谱推荐' }
      },
       // 新增：数据统计子路由
      { 
        path: 'data-statistics', 
        name: 'DataStatistics', 
        component: DataStatistics,
        meta: { title: '数据统计' }
      },
      // 新增：系统设置子路由
      { 
        path: 'system-settings', 
        name: 'SystemSettings', 
        component: SystemSettings,
        meta: { title: '系统设置' }
      }
    ] 
  },
  
   { 
    path: '/login', 
    name: 'LoginView', 
    component: LoginView,
    meta: { title: '用户登录' }
  },
  { 
    path: '/register', 
    name: 'RegisterView', 
    component: RegisterView,
    meta: { title: '用户注册' }
  }
]

const router = createRouter({
  history: createWebHistory(process.env.BASE_URL),
  routes,
})

export default router